#ifndef BUFFER_H_
#define BUFFER_H_

#include <queue>
using namespace std;

/**
 * @brief Dynamic push and pop Buffer for audio samples
 * @author Bernhard Schildendorfer
 *
 * CBuffer provides a fixed length byte-buffer which indicates if it's full.
 *
 * CBuffer contains two FIFO Queues, which are called input-buffer and output-buffer.
 * Data which is written to CBuffer is stored to the input-buffer, data which is
 * read from CBuffer is read from the output-buffer. To transfer data between them,
 * the method processBuffer() needs to be called. Manipulation to the buffer is
 * possible via the byte* of isBufferReady();
 *
 *
 *
 *
 *
 */

class CBuffer {
public:

	CBuffer();
	virtual ~CBuffer();

	/**
	 * Stores pCount bytes in the buffer.
	 *
	 * @param pData    The data to be stored in the buffer
	 * @param pCount   The size of the data to be stored in the buffer
	 * @return         If the buffer is full, a  byte pointer is returned to the
	 *                 beginning of the full buffer, null if buffer is not full
	 */
	void write(const double* pData , unsigned int pCount);

	/**
	 * Receives and removes pCount elements from the output buffer. If there is less
	 * data in the buffer than requested by pCount, additional zeros will be written.
	 *
	 * @param pData    The array that the retrieved data is written on
	 * @param pCount   The size of the data array
	 */
	void read(double* pData, unsigned int pCount);


	/**
	 * Get pCount elements of the unprocessed buffer. Elements of the input buffer are
	 * deleted.
	 *
	 * @param pCount    The amount of elements to be retrieved
	 * @return          The retrieved buffer elements
	 */
	double* getUnprocessedBuffer(unsigned int pCount);
	//Writes pCount data from the input-buffer to the output-buffer
	//If there is not enough data in the input-buffer, NULL is returned

	/**
	 * Writes pCount elements into the output buffer.
	 *
	 * @param pData    The data to be written into the buffer
	 * @param pCount   The size of the data array
	 */
	void putProcessedBuffer(double* pData, unsigned int pCount);

	/**
	 * Returns the number of elements in the input buffer.
	 */
	unsigned int getInputBufferSize();

	/**
	 * Returns the number of elements in the output buffer.
	 */
	unsigned int getOuputBufferSize();

protected:
	queue<double> mInputBuffer;
	queue<double> mOutputBuffer;


};

#endif /* BUFFER_H_ */
